package com.fit.pages.card;

import java.util.List;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.annotations.AnonymousAccess;
import com.fit.annotations.CoachAccess;
import com.fit.annotations.MemberAccess;
import com.fit.dao.card.CardDAO;
import com.fit.entities.card.Card;
import com.fit.pages.ErrorPage;
@AnonymousAccess
@CoachAccess
@MemberAccess

public class Browse {

	@Property
	private List<Card> cards;
	@Property
	private Card card;
	@Inject
	private CardDAO cardDAO;
	@InjectPage
	private ErrorPage errorPage;

	void onActivate() {
		cards = cardDAO.findAll();
	}

	@OnEvent(component = "deleteLink")
	Object onDeleteLink(Long id) {
		try {
			cardDAO.deleteByID(id);
			return null;
		} catch (Exception e) {
			errorPage.setMessage("Greska prilikom brisanja zapisa korisnika! ");
			return errorPage;
		}
	}
}
